'use client';

import React from 'react';
import ShareManage from '@/app/pages/share/ShareManage';
import { Spinner } from '@nextui-org/react';
import { AuthenticationChecker } from '@/app/config/authenticationChecker';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';

export default function SharesPage() {
  const [loading, setLoading] = useState(true);
  const [isAuthenticated, setIsAuthenticated] = useState(false);
  const router = useRouter();

  useEffect(() => {
    const checkAuth = async () => {
      const [authentication] = await AuthenticationChecker();
      setIsAuthenticated(authentication);
      setLoading(false);
      
      if (!authentication) {
        // 未登录，重定向到首页
        router.push('/');
      }
    };
    
    checkAuth();
  }, [router]);

  if (loading) {
    return (
      <div className="flex justify-center items-center h-screen bg-white dark:bg-default-200">
        <Spinner label="加载中..." color="primary" labelColor="primary" size="lg" />
      </div>
    );
  }

  if (!isAuthenticated) {
    return null; // 重定向中，不显示内容
  }

  return <ShareManage />;
} 